// leaderPerson/pages/receivedLeader/receivedLeader.js
var common = require("../../../common/common.js").common;

Page({
    /**
   * 页面的初始数据
   */
    data: {
        page: 1,
        list: []
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.waitPicker();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {
        this.setData({
            page: 1
        });
        this.waitPicker();
        wx.stopPullDownRefresh();
    },
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {
        this.waitPicker();
    },
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    waitPicker: function() {
        let _this = this;
        common.request({
            endpoint: "My/waitpick/mymember_waitpick3",
            method: "post",
            data: {
                openid: wx.getStorageSync("user").openid,
                page: _this.data.page
            },
            header: {
                "content-type": "application/json"
            },
            success: res => {
                var list = res.extra.order;
                list = _this.data.page == 1 ? list : _this.data.list.concat(list);
                _this.setData({
                    list: list,
                    page: _this.data.page + 1,
                    wait_msg: res.extra.wait_msg
                });
            },
            fail(res) {}
        });
    },
    sendLeader: function() {
        let _this = this;
        common.request({
            endpoint: "My/waitpick/send-today-leader",
            method: "post",
            data: {
                openid: wx.getStorageSync("user").openid
            },
            header: {
                "content-type": "application/json"
            },
            success: res => {
                _this.setData({
                    wait_msg: 1
                });
                wx.showToast({
                    icon: "none",
                    title: "已通知用户取货"
                });
            },
            fail(res) {
                wx.showToast({
                    icon: "error",
                    duration: 2e3,
                    title: res.message
                });
            }
        });
    }
});